package com.yanqu.road.server.manger.union.listener;

import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.ICrossUnionSyncListener;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.UnionMgr;

import java.util.List;

public class UnionActivityConditionListener implements ICrossUnionSyncListener {
    @Override
    public void notifySync(int syncType, long playerId, CrossUnionInfo unionInfo, List<CrossUnionMember> memberList) {
        if (syncType == eUnionSyncType.JoinUnion.getValue()) {
            for (CrossUnionMember member : memberList) {
                if (member.getServerId() != GameServer.getInstance().getServerId()) {
                    continue;
                }
                long userId = member.getUserId();
                UnionMgr.memberJoinUnionActivityChange(userId, unionInfo.getUnionUid());
            }
        } else if (syncType == eUnionSyncType.QuitUnion.getValue() || syncType == eUnionSyncType.BeKick.getValue()) {
            for (CrossUnionMember member : memberList) {
                if (member.getServerId() != GameServer.getInstance().getServerId()) {
                    continue;
                }
                long userId = member.getUserId();
                UnionMgr.removeMemberActivityConditionData(userId, unionInfo.getUnionUid());
            }
        } else if (syncType == eUnionSyncType.DeleteUnion.getValue()) {
            GamePlayer player = GamePlayerMgr.getOnlinePlayer(playerId);
            UnionMgr.notifyUnionActivityDeleteRank(player, unionInfo.getUnionUid());
        }
    }
}
